package com.by.interceptor;

import com.by.auto.TokenInterceptorProperties;
import com.by.token.TokenTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * date 2025/2/12 19:13
 * author bjj
 * decoration
 * version 1.0
 * since jdk11
 */
public class TokenWebConfig implements WebMvcConfigurer {
    TokenInterceptorProperties tokenInterceptorProperties;


    TokenTemplate tokenTemplate;

    public TokenWebConfig(TokenInterceptorProperties tokenInterceptorProperties, TokenTemplate tokenTemplate) {
        this.tokenInterceptorProperties = tokenInterceptorProperties;
        this.tokenTemplate = tokenTemplate;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new TokenInterceptor(tokenTemplate))
                .addPathPatterns(tokenInterceptorProperties.getPathPatterns())
                .excludePathPatterns(tokenInterceptorProperties.getExcludePathPatterns());
    }
}
